import React from 'react';

// 用户相关类型
export interface User {
  id: string;
  username: string;
  email: string;
  avatar?: string;
  roles: string[];
  permissions: string[];
  teamIds?: string[];
  createTime: string;
  updateTime: string;
}

// 登录相关类型
export interface LoginForm {
  username: string;
  password: string;
  remember?: boolean;
}

export interface LoginResponse {
  token: string;
  user: User;
  expiresIn: number;
}

// API响应类型
export interface ApiResponse<T = any> {
  code: number;
  message: string;
  data: T;
  timestamp: number;
}

// 分页类型
export interface Pagination {
  current: number;
  pageSize: number;
  total: number;
  showSizeChanger?: boolean;
  showQuickJumper?: boolean;
}

export interface PageRequest {
  page: number;
  size: number;
  sort?: string;
  order?: 'asc' | 'desc';
}

export interface PageResponse<T> {
  content?: T[];  // 兼容旧格式
  records?: T[];  // 新的后端格式
  totalElements: number;
  totalPages: number;
  size: number;
  number: number;
  first: boolean;
  last: boolean;
}

// 菜单类型
export interface MenuItem {
  id: string;
  name: string;
  path: string;
  icon?: string;
  component?: string;
  children?: MenuItem[];
  meta?: {
    title: string;
    requireAuth: boolean;
    roles?: string[];
    keepAlive?: boolean;
  };
}

// 路由类型
export interface RouteConfig {
  path: string;
  component: React.ComponentType;
  exact?: boolean;
  meta?: {
    title: string;
    requireAuth: boolean;
    roles?: string[];
  };
}

// 表格列配置
export interface TableColumn<T = any> {
  title: string;
  dataIndex: keyof T;
  key?: string;
  width?: number;
  align?: 'left' | 'center' | 'right';
  sorter?: boolean;
  render?: (value: any, record: T, index: number) => React.ReactNode;
}

// 表单字段类型
export interface FormField {
  name: string;
  label: string;
  type: 'input' | 'password' | 'select' | 'textarea' | 'date' | 'number';
  required?: boolean;
  placeholder?: string;
  options?: Array<{ label: string; value: any }>;
  rules?: any[];
}

// 系统配置类型
export interface SystemConfig {
  name: string;
  version: string;
  description: string;
  logo?: string;
  theme: {
    primaryColor: string;
    layout: 'side' | 'top' | 'mix';
    navTheme: 'light' | 'dark';
    colorWeak: boolean;
  };
}

// 通知类型
export interface Notification {
  id: string;
  title: string;
  content: string;
  type: 'info' | 'success' | 'warning' | 'error';
  read: boolean;
  createTime: string;
}

// 文件上传类型
export interface UploadFile {
  uid: string;
  name: string;
  status: 'uploading' | 'done' | 'error';
  url?: string;
  size?: number;
  type?: string;
}

// OAuth2相关类型
export interface OAuth2Config {
  clientId: string;
  clientSecret: string;
  redirectUri: string;
  scope: string;
  authorizationUri: string;
  tokenUri: string;
}

export interface OAuth2Token {
  accessToken: string;
  refreshToken: string;
  tokenType: string;
  expiresIn: number;
  scope: string;
}

// 团队相关类型
export interface Team {
  id: string;
  name: string;
  description?: string;
  permissions: string[];
  memberCount: number;
  createTime: string;
  updateTime: string;
  createdBy: string;
}

export interface TeamForm {
  name: string;
  description?: string;
  permissions: string[];
}

export interface TeamMember {
  id: string;
  userId: string;
  teamId: string;
  username: string;
  email: string;
  avatar?: string;
  joinTime: string;
}

// Group类型（保持向后兼容）
export interface Group {
  id: string;
  name: string;
  description?: string;
  permissions: string[];
  memberCount: number;
  createTime: string;
  updateTime: string;
  createdBy: string;
}

export interface GroupForm {
  name: string;
  description?: string;
  permissions: string[];
}

export interface GroupMember {
  id: string;
  userId: string;
  groupId: string;
  username: string;
  email: string;
  avatar?: string;
  joinTime: string;
}

// 导出其他模块的类型
export * from './tenant';
export * from './platform';

// 导出RBAC类型（排除重复的类型）
export type {
  Permission,
  Role,
  Department,
  DepartmentMember,
  Team as RBACTeam,
  TeamMember as RBACTeamMember,
  User as RBACUser,
  Menu,
  UserPermissions,
  OrganizationNode,
  DepartmentForm,
  PermissionAssignForm,
  RoleAssignForm,
  PermissionCheckParams,
  PermissionCheckResult,
  PermissionScope,
  PermissionCondition as RBACPermissionCondition
} from './rbac';